//
//  Utilities.h
//  GeneralDiveUtilitiesTestHarness
//
//  Created by Donald MacKay on 11-04-21.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
/**************************************************************
 * The following contants should eventually move to constants.h 
 *  in the main DecoPlanner project
***************************************************************/
#define LOWER_DEPTH_LIMIT_M 1
#define UPPER_DEPTH_LIMIT_M 100

#define LOWER_DEPTH_LIMIT_I 3
#define UPPER_DEPTH_LIMIT_I 330

#define NITROX32_DEPTH_M    27
#define TRIOX_DEPTH_M       30
#define TRIMIX21_35_DEPTH_M 45
#define TRIMIX18_45_DEPTH_M 60
#define TRIMIX15_55_DEPTH_M 75
#define TRIMIX12_65_DEPTH_M 90
#define TRIMIX10_70_DEPTH_M 100

#define NITROX32_DEPTH_I    90
#define TRIOX_DEPTH_I       100
#define TRIMIX21_35_DEPTH_I 150
#define TRIMIX18_45_DEPTH_I 200
#define TRIMIX15_55_DEPTH_I 250
#define TRIMIX12_65_DEPTH_I 300
#define TRIMIX10_70_DEPTH_I 330

/***************************************************************
 * Some macros to keep the code tidy
 * These should eventually move to constants.h in the main
 * DecoPlanner project
 ***************************************************************/
#define METRIC_TEST(X) (X ? 10 : 33)
/***
 * The MS_ identifiers stands for measurement system
 */
#define MS_TEXT(X) (X ? @"meters" : @"feet")
#define MS_LOWER_DEPTH_LIMIT(X) (X ? LOWER_DEPTH_LIMIT_M : LOWER_DEPTH_LIMIT_I)
#define MS_UPPER_DEPTH_LIMIT(X) (X ? UPPER_DEPTH_LIMIT_M : UPPER_DEPTH_LIMIT_I)

#define MS_NITROX_RANGE(X) (X ? NITROX32_DEPTH_M : NITROX32_DEPTH_I)
#define MS_TRIOX_RANGE(X) (X ? TRIOX_DEPTH_M : TRIOX_DEPTH_I)
#define MS_TRIMIX21_35_RANGE(X) (X ? TRIMIX21_35_DEPTH_M : TRIMIX21_35_DEPTH_I)
#define MS_TRIMIX18_45_RANGE(X) (X ? TRIMIX18_45_DEPTH_M : TRIMIX18_45_DEPTH_I)
#define MS_TRIMIX15_55_RANGE(X) (X ? TRIMIX15_55_DEPTH_M : TRIMIX15_55_DEPTH_I)
#define MS_TRIMIX12_65_RANGE(X) (X ? TRIMIX12_65_DEPTH_M : TRIMIX12_65_DEPTH_I)
#define MS_TRIMIX10_70_RANGE(X) (X ? TRIMIX10_70_DEPTH_M : TRIMIX10_70_DEPTH_I)

#define NITROX32_PERCENT    32
#define OXYGEN100           100

#define FO2_TOO_LOW 100
#define FHE_TOO_LOW 101
#define FO2_TOO_HI  102
#define FH2_TOO_HI  103
#define DEPTH_TOO_SHALLOW   104
#define DEPTH_TOO_DEEP      105
#define IMPOSSIBLE_MIX      106

/***
 * These strings are used for the NSError Object. Eventually
 * they should be moved to the constants.h file of the
 * DecoPlanner project
 */
extern NSString *const kFO2TooLow;
extern NSString *const kFHeTooLow;
extern NSString *const kFO2TooHi;
extern NSString *const kFHeTooHi;
extern NSString *const kDepthTooShallow;
extern NSString *const kDephtTooDeep;
extern NSString *const kImpossibleMix;


@interface GasMix : NSObject {
    NSNumber *oxygenContent;
    NSNumber *heliumContent;
    NSNumber *nitrogenContent;
@private
}

@property (nonatomic, retain) NSNumber * oxygenContent;
@property (nonatomic, retain) NSNumber * heliumContent;
@property (nonatomic, retain) NSNumber * nitrogenContent;

/***
 * Constructors
 */
- (id)initAsNitrox: (double) withFractionOfO2 error:(NSError **)error;
- (id)initAsTriMixWithFO2: (double) fO2 andFractionOfHelium:(double) fHe error:(NSError **)error;
- (id) initWithStdGasForDepth:(double) depth isMetric: (BOOL) metric error:(NSError **)error;
- (id) initAsTriOx;
- (id) initAs21_35;
- (id) initAs18_45;
- (id) initAs15_55;
- (id) initAs12_65;
- (id) initAs10_70;

/***
 * Class methods
 */
+(long) ENDofGasWithFHe: (double) fractionOfHelium atDepthOf: (double) depth isMetric: (BOOL) metric;
+(long) EADofGasWithFN2: (double) fractionOfNitrogen atDepthOf: (double) depth isMetric: (BOOL) metric;

/***
 * Instance methods
 */
-(long) ENDofGas: (double) depth isMetric: (BOOL) metric;
-(long) EADofGas: (double) depth isMetric: (BOOL) metric;
-(double) MOD: (double) atPPO2 isMetric: (BOOL) metric;
-(double) ppO2: (double) atDepth isMetric: (BOOL) metric;
@end